package com.dq.controller.op.opboss.finance;

import com.dq.exception.customException.AdminException;
import com.dq.controller.in.PayrollRecordQuery;
import com.dq.vo.Vo;
import com.dq.domain.org.Org;
import com.dq.domain.record.PayrollRecord;
import com.dq.service.AllService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

/**
 * @Author luchangtong
 * @Date 2019/12/23 17:22
 */
@RestController
@RequestMapping("/sys/boss/PayrollRecord")
@Api(description = "工资单")
public class PayrollRecordController extends AllService {

    @ApiOperation("工资单记录")
    @PostMapping("list")
    public Vo list(@RequestBody PayrollRecordQuery payrollRecordQuery) throws AdminException{
        Org org = null;
        if(payrollRecordQuery.getOrgId() != null){
            org = dao.get(Org.class,payrollRecordQuery.getOrgId());
        }
        return payrollRecordService.findByWhere(payrollRecordQuery,org);
    }

    @PostMapping("/check/{id}")
    @ApiOperation("工资单审批")
    public Vo payrollRecordCheck(@PathVariable Long id) throws AdminException{
        PayrollRecord payrollRecord = dao.get(PayrollRecord.class,id);
        if(payrollRecord == null){
            throw new AdminException("请重新选择");
        }
        payrollRecord.setPayrollStatus(PayrollRecord.PayrollStatus.waitConfirm);
        payrollRecordRepository.save(payrollRecord);
        return new Vo(HttpStatus.OK);
    }
}
